#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "life"
# Date: 2017/1/13

# from tkinter import *
# top = tkinter.Tk()
#
# hello = tkinter.Label(top,text='Hello World!')
# hello.pack()
#
# quit = tkinter.Button(top,text = 'QUIT',command=top.quit,bg='red',fg='white')
# quit.pack(fill=tkinter.X,expand=1)
#
# tkinter.mainloop()

# def resize(ev=None):
#     label.config(font='Helvetica -%d bold'%scale.get())
#
# top = Tk()
# top.geometry('250x150')
#
# label = Label(top,text='Hello World!',font='Helvetica -12 bold')
# label.pack(fill=Y,expand=1)
#
# scale=Scale(top,from_=10,to=40,orient=HORIZONTAL,command=resize)
# scale.set(12)
# scale.pack(fill=X,expand=1)
#
# quit = Button(top,text='QUIT',command=top.quit,activeforeground='red')
# quit.pack()
#
# mainloop()

from functools import partial as pto
from tkinter import Tk,Button,X
from tkinter.messagebox import showinfo, showwarning, showerror
WARN = 'warn'
CRIT = 'crit'
REGU = 'regu'

SIGNS = {
    'do not enter':CRIT,
    'railroad crossing': WARN,
    '55\nspeed limit': REGU,
    'wrong way': CRIT,
    'merging traffic': WARN,
    'one way': REGU,
}

critCB = lambda : showerror('Error','Error Button Pressed!')
warnCB = lambda: showwarning('Warning','Warning Button Pressed!')
infoCB = lambda: showinfo('Info', 'Info Button Pressed!')

top = Tk()
top.title('Road Signs')
Button(top, text='QUIT', command=top.quit, bg='red', fg='white').pack()

MyButton = pto(Button, top)
CritButton = pto(MyButton, command=critCB, bg='white', fg='red')
WarnButton = pto(MyButton, command=warnCB, bg='goldenrod1')
ReguButton = pto(MyButton, command=infoCB, bg='white')

for eachSign in SIGNS:
    signType = SIGNS[eachSign]
    cmd = '%sButton(text=%r%s).pack(fill=X, expand=True)' % (
        signType.title(), eachSign,'.upper()' if signType == CRIT else '.title()')
    eval(cmd)

top.mainloop()